package com.qs.controller;


import com.qs.model.dto.CommentDto;
import com.qs.model.dto.GoodsDetailDto;
import com.qs.model.entity.Comment;
import com.qs.model.vo.CommentVo;
import com.qs.response.Response;
import com.qs.service.ICommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-03-24
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final ICommentService commentService;


    /**
     * 获取商品评论
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/goods/{id}")
    public Response getGoodsComment(@PathVariable("id") Integer id){
        log.info("获取商品评论请求进来------商品id为：{}",id);
        List<CommentDto> result = commentService.findGoodsComment(id);
        log.info("获取商品评论请求成功------商品id为：{}",id);
        return Response.success(result);
    }

    /**
     * 保存商品评论
     * @param
     * @param
     * @param
     * @return
     */
    @PostMapping("/save")
    public Response saveGoodsComment(@RequestBody CommentVo commentVo){
        log.info("保存商品评论请求进来------商品id为：{}",commentVo.getGoodsId());
        commentService.saveGoodsComment(commentVo);
        log.info("保存商品评论请求成功------商品id为：{}",commentVo.getGoodsId());
        return Response.success();
    }
}
